package com.biwano.swapmyjob.objects;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.persistence.jdbc.Index; 

@Entity
public class User {
	
	private String login;
	private String password;
	private String email;
	public boolean company;
	private String locale;
	
	private List<JobExchange> jobExchanges;

	
	
	public User(){}
	public User(String login, String password, String email) {
		this.login=login;
		this.password=password;
		this.email=email;
	}
	@Id	
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String md5password) {
		this.password = md5password;
	}
	@Index(unique=true)		
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	@OneToMany(mappedBy="user")
	public List<JobExchange> getJobExchanges() {
		return jobExchanges;
	}
	public void setJobsExchanges(List<JobExchange> jobs) {
		this.jobExchanges = jobs;
	}
		
	public boolean isCompany() {
		return company;
	}
	public void setCompany(boolean company) {
		this.company = company;
	}
	
	
	public String getLocale() {
		if (StringUtils.isEmpty(locale))
			locale="en";
		return locale;
	}
	public void setLocale(String locale) {
		this.locale = locale;
	}
	@Transient
	public JobExchange getJobExchange()
	{
		if (jobExchanges!=null && !jobExchanges.isEmpty())
		{
			return jobExchanges.get(0);
		}
		return null;
		
	}
}
